import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UserAnswersVO, UserAnswersForm, UserAnswersQuery } from '@/api/answer/userAnswers/types';

/**
 * 查询用户答题记录列表
 * @param query
 * @returns {*}
 */

export const listUserAnswers = (query?: UserAnswersQuery): AxiosPromise<UserAnswersVO[]> => {
  return request({
    url: '/answer/userAnswers/list',
    method: 'get',
    params: query
  });
};

/**
 * 根据用户考试ID查询答题记录列表
 * @param query
 * @returns {*}
 */
export const listUserAnswersByUserExamId = (query?: UserAnswersQuery): AxiosPromise<UserAnswersVO[]> => {
  return request({
    url: '/answer/userAnswers/listByUserExamId',
    method: 'get',
    params: query
  });
};

/**
 * 查询用户答题记录详细
 * @param recordId
 */
export const getUserAnswers = (recordId: string | number): AxiosPromise<UserAnswersVO> => {
  return request({
    url: '/answer/userAnswers/' + recordId,
    method: 'get'
  });
};

/**
 * 新增用户答题记录
 * @param data
 */
export const addUserAnswers = (data: UserAnswersForm) => {
  return request({
    url: '/answer/userAnswers',
    method: 'post',
    data: data
  });
};

/**
 * 修改用户答题记录
 * @param data
 */
export const updateUserAnswers = (data: UserAnswersForm) => {
  return request({
    url: '/answer/userAnswers',
    method: 'put',
    data: data
  });
};

/**
 * 删除用户答题记录
 * @param recordId
 */
export const delUserAnswers = (recordId: string | number | Array<string | number>) => {
  return request({
    url: '/answer/userAnswers/' + recordId,
    method: 'delete'
  });
};
